package cn.jaye.fabric.controller.rest;

import cn.jaye.fabric.application.PeerApplicationService;
import cn.jaye.fabric.application.command.ListPeerByChannelCommand;
import cn.jaye.fabric.application.command.ListPeerCommand;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2018/5/27.
 */
@RestController
@RequestMapping("peer")
public class PeerController {

    @Autowired
    private PeerApplicationService peerApplicationService;

    @PostMapping("list")
    public String list(HttpServletRequest request) {
        String orgId = (String) request.getSession().getAttribute("orgId");
        ListPeerCommand listPeerCommand = new ListPeerCommand();
        listPeerCommand.setOrgId(orgId);
        return JSON.toJSONString(peerApplicationService.list(listPeerCommand));
    }

    @PostMapping("list/channelName")
    public String listByChannelName(HttpServletRequest request, ListPeerByChannelCommand listPeerByChannelCommand) {
        return JSON.toJSONString(peerApplicationService.listByChannel(listPeerByChannelCommand));
    }
}
